﻿@model CurrencyModel
@using Telerik.Web.Mvc.UI;
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("currency-edit").Items(x =>
{
    x.Add().Text(T("Admin.Configuration.Currencies.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
    x.Add().Text(T("Admin.Configuration.Currencies.Sites").Text).Content(TabSites().ToHtmlString());

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "currency-edit"));
})
@helper TabInfo()
{
    @(Html.LocalizedEditor<CurrencyModel, CurrencyLocalizedModel>("currency-info-localized",
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.CmsLabelFor(model => model.Locales[item].Name):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => Model.Locales[item].Name)
                            @Html.ValidationMessageFor(model => model.Locales[item].Name)
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            @Html.HiddenFor(model => model.Locales[item].LanguageId)
                        </td>
                    </tr>
                </table>
                ,
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.CmsLabelFor(model => model.Name):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Name)
                            @Html.ValidationMessageFor(model => model.Name)
                        </td>
                    </tr>
                </table>
            ))
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.CurrencyCode):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.CurrencyCode)
                @Html.ValidationMessageFor(model => model.CurrencyCode)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.Rate):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Rate)
                @Html.ValidationMessageFor(model => model.Rate)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.DisplayLocale):
            </td>
            <td class="adminData">
                @{
                    var cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)
                        .OrderBy(x => x.EnglishName)
                        .Select(x => new SelectListItem()
                                         {
                                             Value = x.IetfLanguageTag,
                                             Text = string.Format("{0}. {1}", x.EnglishName, x.IetfLanguageTag)
                                         });
                }
                @Html.DropDownListFor(model => model.DisplayLocale, cultures)
                @Html.ValidationMessageFor(model => model.DisplayLocale)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.CustomFormatting):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.CustomFormatting)
                @Html.ValidationMessageFor(model => model.CustomFormatting)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.Published):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Published)
                @Html.ValidationMessageFor(model => model.Published)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.DisplayOrder):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.DisplayOrder)
                @Html.ValidationMessageFor(model => model.DisplayOrder)
            </td>
        </tr>
        @if (Model.Id > 0)
        {
            <tr>
                <td class="adminTitle">
                    @Html.CmsLabelFor(model => model.CreatedOn):
                </td>
                <td class="adminData">
                    @Html.DisplayFor(model => model.CreatedOn)
                </td>
            </tr>
        }
    </table>
}

@helper TabSites()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToSites)").click(toggleSiteMapping);
        
            toggleSiteMapping();
        });


        function toggleSiteMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToSites)').is(':checked')) {
                $('#pnl-available-sites').show();
            }
            else {
                $('#pnl-available-sites').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.LimitedToSites):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToSites)
                @Html.ValidationMessageFor(model => model.LimitedToSites)
            </td>
        </tr>
        <tr id="pnl-available-sites">
            <td class="adminTitle">
                @Html.CmsLabelFor(model => model.AvailableSites):
            </td>
            <td class="adminData">
                @if (Model.AvailableSites != null && Model.AvailableSites.Count > 0)
                {
                    foreach (var site in Model.AvailableSites)
                    {
                    <div>
                        <input type="checkbox" name="SelectedSiteIds" value="@site.Id" checked="@(Model.SelectedSiteIds != null && Model.SelectedSiteIds.Contains(site.Id))" />@site.Name
                    </div>
                    }
                }
                else
                {
                    <div>No sites defined</div>
                }</td>
        </tr>
    </table>
}
